package com.gxuwz.Market.business.dao;

import org.springframework.stereotype.Repository;

import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.gxuwz.Market.business.entity.ServiceStudio;
import com.gxuwz.core.dao.impl.BaseDaoImpl;
import com.gxuwz.core.pagination.Result;



@Repository("serviceStudioDAO")
public class ServiceStudioDAO extends BaseDaoImpl<ServiceStudio>{
	/**
	 * 根据条件查找分页
	 * @param serviceStudio 模型
	 * @param page 第几页
	 * @param row 长度
	 * @return
	 * @author 李宪乾
	 * @date 2017.9.27
	 */
	@SuppressWarnings("unchecked")
	public Result<ServiceStudio> find(ServiceStudio serviceStudio, int page, int size){
		String queryString = "from ServiceStudio where 1=1";
		if(null != serviceStudio.getStudioId() && !"".equals(serviceStudio.getStudioId())){			
			queryString = queryString + "and studioId like '%"+serviceStudio.getStudioId()+"%'";
		}
		if(null != serviceStudio.getStudioName() && !"".equals(serviceStudio.getStudioName())){
			queryString = queryString +" and studioName like '%"+serviceStudio.getStudioName()+"%'";
		}
		if(null != serviceStudio.getAddress() && !"".equals(serviceStudio.getAddress())){
			queryString = queryString +" and address like '%"+serviceStudio.getAddress()+"%'";
		}
		int start=(page-1)*size;
		int limit =size;
		return (Result<ServiceStudio> )super.find(queryString, null, null, start, limit);
	}
	
	public List<ServiceStudio> findAll() {
		List<ServiceStudio> serviceClassList = null;
		String queryString = "from ServiceStudio where 1=1";
		serviceClassList = this.getHibernateTemplate().find(queryString);
		return serviceClassList;
	}
	/**
	 * 根据id查询单个用户
	 * @param userId
	 * @return
	 */
	public ServiceStudio findById(int id){
		List<ServiceStudio> serviceClassList = null;
		String queryString = "from ServiceStudio where id ="+id;
		try{
			serviceClassList = this.getHibernateTemplate().find(queryString);
		}catch(Exception e){
			System.out.println(e);
		}
		return serviceClassList.get(0);
	}
	
	public List<ServiceStudio> findByProperty(String property, String value){
		List<ServiceStudio> list = null;
		String queryString = "from ServiceStudio where "+property+" ='"+value+"' ";
		try{
			list = this.getHibernateTemplate().find(queryString);
		}catch(Exception e){
			System.out.println(e);
		}
		return list;
	}
}